import sys,SocketServer
    
annuaire = {"Standard"  : 6500,
            "Bidet"     : 6560,
            "Boimon"    : 6562,
            "Cottenceau": 6563,
            "Declerck"  : 6568,
            "Godon"     : 6570,
            "Hardouin"  : 6564,
            "Ferrier"   : 6574,
            "Lahaie"    : 6565} 


class MyTCPHandler(SocketServer.BaseRequestHandler):
	def handle(self):
		self.data = self.request.recv(1024).strip()
		print "received from ",self.client_address[0], ": ", self.data
		if self.data.upper() == "ALL":
			ch = ""
			for i in annuaire.keys() :
				ch += i + " / "

			self.request.send(ch)
		else:
			if self.data in annuaire:
				self.request.send(str(annuaire[self.data]))
			else:
				self.request.send("Error")
		
#Main

try : 
	HOST,PORT = "localhost",int(sys.argv[1])
	server = SocketServer.TCPServer((HOST,PORT),MyTCPHandler)
	server.serve_forever()
	
except KeyboardInterrupt:
	server.socket.close()